from threading import settrace

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.fields.simple import TextAreaField
from wtforms.validators import Length, EqualTo, Email, DataRequired, ValidationError

from App.models import User

class RegisterForm(FlaskForm):
    def validate_username(self, username_check):
        if User.query.filter_by(username=username_check.data).first():
            raise ValidationError('用户名已经被注册！请尝试一个不同的用户名。')
    
    def validate_email_address(self, email_address_check):
        if User.query.filter_by(email_address=email_address_check.data).first():
            raise ValidationError('邮箱已经被注册！请尝试一个不同的邮箱。')

    username = StringField(label='User Name', validators=[Length(min=2, max=30), DataRequired()])
    email_address = StringField(label='Email Address', validators=[Email(), DataRequired()])
    password1 = PasswordField(label='Password', validators=[Length(min=3), DataRequired()])
    password2 = PasswordField(label='Confirm Password', validators=[EqualTo('password1'), DataRequired()])
    submit = SubmitField(label='确认注册')

class LoginForm(FlaskForm):
    username = StringField(label='User Name', validators=[DataRequired()])
    password = PasswordField(label='Password', validators=[DataRequired()])
    submit = SubmitField(label='确定')

class PurchaseItemForm(FlaskForm):
    submit = SubmitField(label='Purchase Item!')

class SellItemForm(FlaskForm):
    submit = SubmitField(label='Sell Item!')
# //初始网站基础参数


class SettingForm(FlaskForm):


    db_base_url = StringField(label='Base URL' )
    db_api_key = StringField(label='API Key')
    azure_region = StringField(label='Azure Region')
    azure_ttsapi_key = StringField(label='Azure TTS API Key')

    azure_voice_name = StringField(label='微软语音类型')
    init_prompt = TextAreaField(label='初始化提示语')

    start_prompt = StringField(label='开始提示语模板', render_kw={"placeholder": "添加默认提示词"})

    video_scripts = StringField(label='视频脚本')

    submit = SubmitField(label='提交')
    create_video_script = SubmitField(label='生成视频脚本')
    tts_video_script = SubmitField(label='生成视频配音')



